package JdkDateDemo4;

import java.time.Instant;
import java.time.ZoneId;
import java.time.ZonedDateTime;

public class InstantDemo1 {
    public static void main(String[] args) {

        /*
            static Instant now()                      获取时间的Instant对象(标准时间)
            static Instant ofEpochMilli(long epochMilli) 根据(秒/毫秒/纳秒)获取Instant对象
            ZonedDateTime atZone(ZoneId zone)          把Instant转成指定时区的时间
            boolean isXxx(Instant otherInstant)        判断系列的方法
            Instant minusXxx(long millisToSubtract)    减少时间系列的方法
            Instant plusXxx(long millisToAdd)          增加时间系列的方法
        */
        //1.获取Instant对象
        //Instant now=Instant.now();
        //System.out.println(now);
        //2.根据(秒/毫秒/纳秒)获取Instant对象
        Instant instant1=Instant.ofEpochMilli(0L);
        System.out.println(instant1);
        Instant instant2=Instant.ofEpochSecond(1L);
        System.out.println(instant2);
        Instant instant3=Instant.ofEpochSecond(1L,1000000000L);
        System.out.println(instant3);
        //指定时区
        ZonedDateTime time=Instant.now().atZone(ZoneId.of("Asia/Shanghai"));
        System.out.println(time);
        //isXxx判断
        //是否在前
        Instant instant4=Instant.ofEpochMilli(0L);
        Instant instant5=Instant.ofEpochMilli(1000L);
        boolean result1=instant4.isBefore(instant5);
        System.out.println(result1);
        //是否在后
        boolean result2=instant4.isAfter(instant5);
        System.out.println(result2);
        //minusXxx
        Instant instant6=Instant.ofEpochMilli(0L);
        Instant instant7=instant6.minusMillis(-1L);
        System.out.println(instant7);
    }
}
